<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>批次号：</label>
                                <input type="text" name="batchNo"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="state" th:with="type=${@dict.getType('data_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="central:centralProduct:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="central:centralProduct:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                    <a class="btn btn-success multiple disabled" onclick="$.operation.handleStateToAvailable()" shiro:hasPermission="central:centralProduct:edit">
                        <i class="fa fa-edit"></i> 启用
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operation.handleStateToDisabled()" shiro:hasPermission="central:centralProduct:edit">
                        <i class="fa fa-edit"></i> 禁用
                    </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operation.removeAll()" shiro:hasPermission="central:centralProduct:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.operation.importExcel()" shiro:hasPermission="central:centralProduct:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.operation.exportExcel()" shiro:hasPermission="central:centralProduct:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('central:centralProduct:edit')}]];
        var removeFlag = [[${@permission.hasPermi('central:centralProduct:remove')}]];

        var stateDatas = [[${@dict.getType('data_normal_disable')}]];
        var materialStatusDatas = [[${@dict.getType('central_material_status')}]];
        var inputStatusDatas = [[${@dict.getType('central_input_status')}]];
        const taskStatusList = [[${@dict.getType('sys_task_status')}]];


        $(function() {
            var options = {
                requestPrefix: ctx + "central/centralProduct",
                uniqueId:'id',
                modalName: "产品",
                signName: "top_central_product",
                logicDelete:true,
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [
                    {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: false,
                    sortable:true,
                },
                {
                    field: 'batchNo',
                    title: '产品批次号',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'typeId',
                    title: '产品类型',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip($.common.getItemField(row.productType,'name'));
                    }
                },
                {
                    field: 'syntheticStatus',
                    title: '合成加工状态',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.selectDictLabel(taskStatusList, value);
                    }
                },
                {
                    field: 'state',
                    title: '状态',
                    sortable:true,
                    formatter: function(value, row, index) {
                        if($.logicDelete.isDelFlag()){
                            return $.table.selectDictLabel(stateDatas, value);
                        }else{
                            return $.operation.stateTools(row);
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true,
                    visible: false,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'updateTime',
                    title: '修改时间',
                    sortable:true,
                    visible: false,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'weight',
                    title: '权重',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'remark',
                    title: '描述',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if($.logicDelete.isDelFlag()){
                            actions.push('<a class="btn btn-success btn-xs ' + restoreFlag + '" href="javascript:void(0)" onclick="$.operation.restoreData(\'' + row.id + '\')"><i class="fa fa-edit"></i>恢复</a> ');
                        }else{
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operation.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            console.log("index, row, $detail",index, row, $detail)
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: ctx + "central/centralMaterial/list",
                sidePagination: "server",
                uniqueId:'id',
                queryParams : {
                    batchNo: row.batchNo
                },
                columns: [
                    {
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '编号',
                        visible: true,
                        sortable:true,
                    },
                    {
                        field: 'batchNo',
                        title: '物料批次号',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.tooltip(value);
                        }
                    },
                    {
                        field: 'typeId',
                        title: '物料类型名称',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.tooltip($.common.getItemField(row.materialType,'name'));
                        }
                    },
                    {
                        field: 'parentTypeId',
                        title: '合成物料名称',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.tooltip($.common.getItemField(row.parentMaterialType,'name'));
                        }
                    },
                    {
                        field: 'createType',
                        title: '录入类型',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.selectDictLabel(inputStatusDatas,value);
                        }
                    },
                    {
                        field: 'materialStatus',
                        title: '物料状态',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.selectDictLabel(materialStatusDatas,value);
                        }
                    },
                    {
                        field: 'state',
                        title: '状态',
                        sortable:true,
                        formatter: function(value, row, index) {
                            if($.logicDelete.isDelFlag()){
                                return $.table.selectDictLabel(stateDatas, value);
                            }else{
                                return $.operation.stateTools(row);
                            }
                        }
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sortable:true,
                        visible: false,
                        formatter: function(value,row,index){
                            return $.table.tooltip(value);
                        }
                    },
                    {
                        field: 'updateTime',
                        title: '修改时间',
                        sortable:true,
                        visible: false,
                        formatter: function(value,row,index){
                            return $.table.tooltip(value);
                        }
                    },
                    {
                        field: 'remark',
                        title: '描述',
                        sortable:true,
                        formatter: function(value,row,index){
                            return $.table.tooltip(value);
                        }
                    }]
            });
        };

        // initChildTable = function(index, row, $detail) {
        //     var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        //     $(childTable).bootstrapTable({
        //         url: ctx + "demo/table/list",
        //         method: 'post',
        //         sidePagination: "server",
        //         contentType: "application/x-www-form-urlencoded",
        //         queryParams : {
        //             userName: '测试8'
        //         },
        //         columns: [{
        //             field : 'userId',
        //             title : '子表ID'
        //         },
        //             {
        //                 field : 'userCode',
        //                 title : '子表编号'
        //             },
        //             {
        //                 field : 'userName',
        //                 title : '子表姓名'
        //             }]
        //     });
        // };
    </script>
</body>
</html>